/**
 * 
 */
package datastructure.impl;

import java.lang.reflect.Array;
import java.util.ArrayList;

import com.sun.org.apache.bcel.internal.generic.NEW;

import datastructure.Stack;

/**
 * @author Jun
 *
 */
public class SeqStack<T> implements Stack<T> {

	private int MAXNUM = 100;
	private int t ;
	private T[] s;
	
	@SuppressWarnings("unchecked")
	public SeqStack(T e){
		
		t = -1;
		s = (T[])Array.newInstance(e.getClass(), MAXNUM);
//		s = (T[])new Object[MAXNUM];
	}
	
	@SuppressWarnings("unchecked")
	public SeqStack (Class e){
		
		t = -1;
		s = (T[])Array.newInstance(e, MAXNUM);
		
	}
	
//	public <T> SeqStack() {
//		// TODO Auto-generated constructor stub
//		t= -1;
//		
//		
//	}

	@Override
	public boolean isEmptyStack() {
		// TODO Auto-generated method stub
		return (t == -1);
	}

	@Override
	public boolean pop() {
		// TODO Auto-generated method stub
		if(t== -1) return false;
		else 
			t = t -1;
		return true;
	}

	@Override
	public void push(T item) {
		// TODO Auto-generated method stub
		if( t >= MAXNUM -1){
			System.out.println("Overflow!");
		}
		else {
			t += 1;
			s[t] = item;
		}
	}

	@Override
	public T top() {
		// TODO Auto-generated method stub
		if(t==-1) return null;
		else
			return s[t];
	}

}
